package mx.com.switz.dao.Impl;

import java.util.List;
import javax.sql.DataSource;
import mx.com.switz.dao.CanastaDao;
import mx.com.switz.dto.Canasta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;


@Repository
public class CanastaDaoImpl extends JdbcDaoSupport implements CanastaDao{

	
private SimpleJdbcInsert simpleJdbcInsert;
    
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
    
    @Autowired
    public CanastaDaoImpl(DataSource dataSource){
    	
    	
    	setDataSource(dataSource);
        this.namedParameterJdbcTemplate = new NamedParameterJdbcTemplate(
                dataSource);
        simpleJdbcInsert = new SimpleJdbcInsert(getJdbcTemplate().getDataSource()).withTableName("Canasta");
    }
    
    public void insertCanasta(Canasta canasta) {
        SqlParameterSource parameters = new BeanPropertySqlParameterSource(canasta);
        simpleJdbcInsert.execute(parameters);
    }

    public List selectCanasta(Canasta canasta) {        
        
        
        String query = "SELECT * FROM  canasta WHERE clave = :clave" ;
        SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(canasta);
        return  namedParameterJdbcTemplate.query(query, parameterSource,ParameterizedBeanPropertyRowMapper.newInstance(Canasta.class));

            
    }

    
    
}
